﻿using Eagles.Base.DataBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Eagles.DomainService.Model.User;

namespace Eagles.Application.Job.DataAccess
{
    public class UserInfoDataAccess
    {

        private readonly IDbManager dbManager;

       

        public  UserInfoDataAccess(IDbManager dbManager)
        {
            this.dbManager = dbManager;
        }

        public  List<TbUserInfo> GetUserInfoList()
        {
            var sql = new StringBuilder();
           

            sql.AppendFormat(@"  SELECT a.OrgId, a.BranchId, a.UserId, a.Password, a.Name, a.Sex, a.Ethnic, a.Birthday, a.Origin, a.OriginAddress,
a.Phone, a.IdNumber, a.Education, a.School, a.Provice, a.City, a.District, a.Address, a.Company, a.Dept, a.Title, a.PreMemberTime, a.MemberTime, a.MemberType,
a.Status, a.MemberStatus, a.PhotoUrl, a.NickPhotoUrl, a.CreateTime, a.EditTime, a.OperId, a.IsCustomer, a.Score, a.IsLeader, a.LoginErrorCount, a.LockingTime, b.BranchName,a.FeeExpireDate,o.FeeExpireNoticeDay,o.FeeNotice
FROM eagles.tb_user_info a inner join eagles.tb_branch b on a.BranchId=b.BranchId   inner join  eagles.tb_org_info o on o.OrgId=a.OrgId where a.Status=0    ");

            return dbManager.Query<TbUserInfo>(sql.ToString());
            // throw new NotImplementedException();
        }



        public void SendUserNotice(TbUserNotice notice)
        {

            dbManager.Excuted(@"INSERT INTO `eagles`.`tb_user_notice`
(`OrgId`,
`NewsId`,
`NewsType`,
`Title`,
`UserId`,
`Content`,
`TargetUrl`,
`IsRead`,
`FromUser`,
`CreateTime`,
`ReadTime`)
VALUES
(@OrgId,
@NewsId,
@NewsType,
@Title,
@UserId,
@Content,
@TargetUrl,
@IsRead,
@FromUser,
now(),
now());
", notice);

        }

    }
}
